<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>timer.html</title>

		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="this is my page">
		<meta http-equiv="content-type" content="text/html; charset=UTF-8">

		<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
		<script type="text/javascript">
		var daySeconds=60*60*24;
		var hourSeconds=60*60;	
		var sum=0;
		var day="0";
		var hours="0";
		var minutes="0";
		var seconds="0";
		var timmer;
		function doTime(){
			day=document.getElementById("day").value;
			//alert(day);
			hours=document.getElementById("hour").value;
			//alert(hours);
			minutes=document.getElementById("minute").value;
			//alert(minutes);
			seconds=document.getElementById("second").value;
			//alert(day+hours+minutes+seconds);			
			sum=eval(seconds+"+"+minutes+"*60+"+hours+"*60*60+"+day+"*60*60*24")
			var button=document.getElementById("button");
			button.onclick=pause;
			button.value="暂停计时"
			timmer=setInterval("timer()",1000);
		}
		
		function timer(){			
			seconds=eval(seconds+"-1");
			if(seconds<=-1){//如果秒不够				
				minutes=eval(minutes+"-1");
				if(minutes>=0){
					seconds=59;
				}else if(minutes<=-1){
					hours=eval(hours+"-1");
					if(hours>=0){
						seconds=59
						minutes=59;
					}else if(hours<=-1){
						day=eval(day+"-1");							
						if(day>=0){
							seconds=59;
							minutes=59;
							hours=23;
						}else if(day<=-1){
								day=0;
								hours=0;
								minutes=0;
								seconds=0;
								clearInterval(timmer);
								alert("once");
						}
					}
				}
			}				
			var leftTime=document.getElementById("leftTime");
			leftTime.innerHTML= day+" day " +hours+" hour "+ minutes+" minutes "+ seconds +" seconds ";		
		}
		
		function pause(){			
			clearInterval(timmer);
			var button=document.getElementById("button");
			button.onclick=continues;
			button.value="继续计时"
		}
		
		function continues(){
			var button=document.getElementById("button");
			button.onclick=pause;
			button.value="暂停计时"
			timmer=setInterval("timer()",1000);
		}
		
	</script>
	</head>

	<body>
		<br>
		<br>
		<input id="day" type="text" maxlength="3" size="5"></input>
		<input id="hour" type="text" maxlength="3" size="5"></input>
		<input id="minute" type="text" maxlength="3" size="5"></input>
		<input id="second" type="text" maxlength="3" size="5"></input>
		<input id="button" type="button" value="开始计时" onClick="doTime();"></input>
		<label id="leftTime"></label>
	</body>
</html>
